// pages/search/search.js
var util = require('../../utils/network.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wayPoint:[
        { way: '大港客运站' },
        { way: '大港客运站' },
        { way: '大港客运站' },
        { way: '大港客运站' },
        { way: '大港客运站' },
    ],
    gotime:[
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
        { time: '05:30' },
    ],
    footer:[
        { imgUrl: '../../image/sy_time.png', text: '时间' },
        { imgUrl: '../../image/sy_price.png', text: '价格' },
        { imgUrl: '../../image/sy_qbbc.png', text: '全部班次' },
        { imgUrl: '../../image/sy_bussd.png', text: '车站' }
    ]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       const departCityInfo = wx.getStorageSync('departCityInfo')
       const reachCityInfo = wx.getStorageSync('reachCityInfo')
       const currentDepartDate = wx.getStorageSync("currentDepartDate")

       console.log(departCityInfo)
       console.log(reachCityInfo)
       console.log(currentDepartDate)
       
    
      let data = {
          "departid": departCityInfo.id,//出发地id
          "departname": departCityInfo.findname,//出发地名称
          "departtype": departCityInfo.departtype || departCityInfo.deptarttype,//出发地类型
          "destination": reachCityInfo.name,//目的地
          "destinationid": reachCityInfo.cityid,//目的地id
          "destinationtype": reachCityInfo.destinationtype,//目的地类型
          "departdate": currentDepartDate.yearmothday,//出发日期
          "netname": departCityInfo.netname,//出发地域名还是到达地域名
          "showType": 2,//显示类型固定值(2)
          "token": '{ "clienttype":"web", "ordertoken":"undefined", "clienttoken":"null"}'
        };

      // let data = {
      //   "departid": '220100000000',//出发地id
      //   "departname": '长春市',//出发地名称
      //   "departtype": 1,//出发地类型
      //   "destination": '通化',//目的地
      //   "destinationid": '',//目的地id
      //   "destinationtype": 2,//目的地类型
      //   "departdate": '2018-03-29',//出发日期
      //   "netname": 'nmd.bus365.cn',//出发地域名还是到达地域名
      //   "showType": 2,//显示类型固定值(2)
      //   "token": '{ "clienttype":"web", "ordertoken":"undefined", "clienttoken":"null"}'
      // };

      var token = util.token;
      wx.request({
        url: util.main + '/schedulesearch', 
        data,
          header: {
              "content-type": "application/json",
              "accept": "application/json,",
          },
          method: "GET",
          dataType: "json",
          success: (res) => {
            const { schedules, altermessage } = res.data
            this.setData({
              schedules,
              altermessage
            })
          }
      })
    wx.setNavigationBarTitle({
        title: departCityInfo.findname + '-' + reachCityInfo.name,
    })
  },
  godate:function(){
      wx.navigateTo({
          url: '../date/date',
      })
  },
  selectTime:function(){
      wx.navigateTo({
          url: '../flights/flights',
      })
  },
  toSearchdetail:function(){
      wx.navigateTo({
          url: '../search-xiangqing/search-xiangqing',
      })
  },
  toOrderwrite:function(){
      wx.navigateTo({
          url: '../orderwrite/orderwrite',
      })
  }
})